import React from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import routes from './router/router';
import Auth from './router/Auth';

function App() {
  return (
    <div>
      <BrowserRouter>
        <Switch>
          {routes.map((route, index) => {
            const { component: Component } = route;
            return (
              <Route
                key={index}
                path={route.path}
                exact
                render={(props) => {
                  document.title = route.meta.title;
                  return (
                    <Auth {...route}>
                      <Component {...props} />
                    </Auth>
                  );
                }}
              />
            );
          })}
          <Route render={() => <h1>404 not found！</h1>} />
        </Switch>
      </BrowserRouter>
    </div>
  );
}

export default App;
